﻿namespace TrinityEngine
{
    public abstract class Component
    {
        public Transform transform;

        public bool enabled
        {
            get
            {
                return _enabled;
            }
            set
            {
                _enabled = value;
                if (_enabled)
                {
                    CallOnEnable();
                }
                else
                {
                    CallOnDisable();
                }
            }
        }
        private bool _enabled = true;

        protected virtual void Awake() { }

        protected virtual void Update() { }

        protected virtual void OnEnable() { }

        protected virtual void OnDisable() { }

        protected virtual void OnDestroy() { }

        public void CallAwake()
        {
            Awake();
            OnEnable();
        }

        public void CallUpdate()
        {
            if (!enabled)
            {
                return;
            }

            Update();
        }

        public void CallOnEnable() => OnEnable();

        public void CallOnDisable() => OnDisable();

        public void CallOnDestroy() => OnDestroy();
    }
}
